﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeSaveNewGRNDataAction : BestLifeDataAction<int>
    {

        private GRN GvGrn;
        private string Gvxml;
        //private List<string> GvList;

        public BestLifeSaveNewGRNDataAction(GRN PGrn, string Pxml)
        {

            GvGrn = PGrn;
            Gvxml = Pxml;
            //GvList = PList;

        }

        public override int Body(SqlConnection PConn)
        {
            try
            {
                //string LvS = string.Join(",", GvList);
                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.InsertGRNDetails";

                LvCommand.Parameters.Add(new SqlParameter("@GRN_Id", GvGrn.GRN_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Branch_Id", GvGrn.Branch_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Sup_ID", GvGrn.Sup_ID.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@PO_Id", GvGrn.PO_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Total", decimal.Parse(GvGrn.Total.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Sup_Bill_No", GvGrn.Sup_Bill_No.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Book_GRNno", GvGrn.Book_GRNno.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvGrn.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Create_Date", DateTime.Parse(GvGrn.Date_Create.ToString())));

                LvCommand.Parameters.Add(new SqlParameter("@grndetails", Gvxml));
                //LvCommand.Parameters.Add(new SqlParameter("@prlist", LvS));



                int LvCount = LvCommand.ExecuteNonQuery();
                return LvCount; 

            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
